home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Revolution - Das Atari CD Magazin 1997
/
Revolution - Das Atari CD Magazin 1.iso
/
software
/
anwendng
/
qed_397
/
sourcen
/
av.c
< prev
next >
Wrap
C/C++ Source or Header
|
1997-01-14
|
9KB
|
419 lines
#include "global.h"
#include "comm.h"
#include "dd.h"
#include "debug.h"
#include "disk.h"
#include "options.h"
#include "rsc.h"
#include "windows.h"
#include "av.h"
#ifdef DEBUG
#undef DEBUG_AV
#endif
/* exportierte Variablen *****************************************************/
GLOBAL WORD av_shell_id = -1, /* ID des Desktops */
av_shell_status = 0; /* Welche AV_* kann Desktop */
/* Hilfe-System **************************************************************/
#ifndef AC_HELP
#define AC_HELP 1025
#endif
/*
* Generiert aus einem Pfadnamen den GEM-Namen (max. acht Zeichen, ggf.
* mit ' ' aufgefüllt) und überprüft ihn auf ST-GUIDE.
*/
LOCAL BOOLEAN make_name(UBYTE *longname, UBYTE *shortname, BOOLEAN must_stg)
{
WORD len, i;
UBYTE *p;
if (longname[0] == EOS)
{
note(1, NOHELP);
strcpy(shortname, "");
return FALSE;
}
else
{
file_name(longname, shortname, FALSE);
str_upper(shortname);
p = strrchr(shortname, '.'); /* Extension abschneiden */
*p = '\0';
len = (short) strlen(shortname);
for (i = len; i < 8; i++)
strcat(shortname, " ");
if (must_stg && (strcmp(shortname, "ST-GUIDE") != 0))
{
note(1, NOSTG);
return FALSE;
}
else
return TRUE;
}
}
/*
* Liefert die app_id des übergebenen Programmes zurück. Falls es noch
* nicht läuft, wird es mit arg gestartet.
*/
LOCAL WORD get_id(UBYTE* name, UBYTE *path, UBYTE *arg, BOOLEAN *started)
{
WORD ret = -1;
UBYTE *p, help[128] = "";
BOOLEAN s = FALSE;
if (name[0] != EOS)
{
ret = appl_find(name);
if (ret < 0) /* ggf. als Programm nachstarten */
{
if (arg != NULL)
{
strcpy(help, " ");
strcat(help, arg);
help[0] = (UBYTE)strlen(help);
}
p = strrchr(path, '.');
if (file_exist(path) && ((strncmp(p, ".APP", 3) == 0) || (strncmp(p, ".PRG", 3) == 0) ||
(strncmp(p, ".app", 3) == 0) || (strncmp(p, ".prg", 3) == 0)))
{
if (aes41)
{
ret = shel_write(1, 1, 1, path, help);
s = (ret > 0);
}
else if (magx)
{
ret = shel_write(1, 1, 100, path, help);
s = (ret > 0);
}
else
{
note(1, HELPSTART);
ret = -1;
}
}
else
{
snote(1, HELPNOTF, helpprog);
ret = - 1;
}
}
}
if (started != NULL)
*started = s;
return ret;
}
LOCAL VOID send_help(WORD id, CONST UBYTE *str)
{
memset(msgbuff, 0, (WORD)sizeof(msgbuff));
msgbuff[0] = AC_HELP;
msgbuff[1] = gl_apid;
strcpy(global_str1, str);
*(UBYTE **)(msgbuff + 3) = global_str1;
send_msg(id);
}
GLOBAL BOOLEAN call_help(CONST UBYTE *str)
{
WORD help_id;
FILENAME name;
Wake_mouse();
if (make_name(helpprog, name, FALSE))
{
help_id = get_id(name, helpprog, NULL, NULL);
if (help_id > 0)
{
send_help(help_id, str);
return TRUE;
}
}
return FALSE;
}
GLOBAL BOOLEAN call_hyp(CONST UBYTE *data)
{
WORD stg_id;
UBYTE help[256];
FILENAME name;
BOOLEAN started;
if (helpprog[0] == EOS)
{
note(1, NOHELP);
return FALSE;
}
Wake_mouse();
if (make_name(helpprog, name, TRUE))
{
strcpy(help, "*:\\QED.HYP ");
strcat(help, data);
stg_id = get_id(name, helpprog, help, &started);
if (stg_id > 0 && !started) /* nicht gestartet, da es bereits lief! */
send_vastart(stg_id, help); /* -> also Message schicken */
return (stg_id > 0);
}
return FALSE;
}
LOCAL VOID get_my_name(UBYTE *my_name)
{
UBYTE str[12];
WORD d, i, id;
if ((appl_xgetinfo(4, &d, &d, &i, &d)) && (i == 1)) /* gibts appl_search? */
{
i = appl_search(0, str, &d, &id);
while (i != 0)
{
if (id == gl_apid)
break;
i = appl_search( 1, str, &d, &id);
}
}
if (i != 0)
{
strcpy(my_name, str);
for (i = (WORD)strlen(my_name); i < 8; i++)
strcat(my_name, " ");
}
else
strcpy(my_name, "");
#ifdef DEBUG_AV
Debug("get_my_name()= %s.\n", my_name);
#endif
}
/* AV-Protokoll **************************************************************/
LOCAL UBYTE *glob_data = NULL;
LOCAL VOID send_avprot(VOID)
{
if (av_shell_id >= 0)
{
memset(msgbuff, 0, (WORD)sizeof(msgbuff));
msgbuff[0] = AV_PROTOKOLL;
msgbuff[1] = gl_apid;
msgbuff[3] = (2|16); /* VA_START, Quoting */
/*
#ifdef DEBUG
strcpy(global_str1, "QED_NEU ");
#else
strcpy(global_str1, "QED ");
#endif
*/
get_my_name(global_str1);
*(UBYTE **) (msgbuff + 6) = global_str1;
send_msg(av_shell_id);
#ifdef DEBUG_AV
Debug("qed: AV_PROTOKOLL\n");
#endif
}
}
LOCAL VOID send_avexit(VOID)
{
if ((av_shell_id >= 0) && (av_shell_status & 1024))
{
memset(msgbuff, 0, (WORD)sizeof(msgbuff));
msgbuff[0] = AV_EXIT;
msgbuff[1] = gl_apid;
msgbuff[3] = gl_apid;
send_msg(av_shell_id);
#ifdef DEBUG_AV
Debug("qed: AV_EXIT\n");
#endif
}
}
GLOBAL BOOLEAN send_avkey(WORD ks, WORD kr)
{
BOOLEAN b = FALSE;
if ((av_shell_id >= 0) && (av_shell_status & 1))
{
Wake_mouse();
memset(msgbuff, 0, (WORD)sizeof(msgbuff));
msgbuff[0] = AV_SENDKEY;
msgbuff[1] = gl_apid;
msgbuff[3] = ks;
msgbuff[4] = kr;
b = send_msg(av_shell_id);
#ifdef DEBUG_AV
Debug("qed: AV_SENDKEY (%d,%d)\n", ks, kr);
#endif
}
return b;
}
GLOBAL VOID send_avwinopen(WORD handle)
{
if ((av_shell_id >= 0) && (wind_cycle)) /* Fensterwechsel global */
{
memset(msgbuff, 0, (WORD)sizeof(msgbuff));
msgbuff[0] = AV_ACCWINDOPEN;
msgbuff[1] = gl_apid;
msgbuff[3] = handle;
send_msg(av_shell_id);
#ifdef DEBUG_AV
Debug("qed: AV_ACCWINDOPEN (%d)\n", handle);
#endif
}
}
GLOBAL VOID send_avwinclose(WORD handle)
{
if ((av_shell_id >= 0) && (wind_cycle)) /* Fensterwechsel global */
{
memset(msgbuff, 0, (WORD)sizeof(msgbuff));
msgbuff[0] = AV_ACCWINDCLOSED;
msgbuff[1] = gl_apid;
msgbuff[3] = handle;
send_msg(av_shell_id);
#ifdef DEBUG_AV
Debug("qed: AV_ACCWINDCLOSED (%d)\n", handle);
#endif
}
}
GLOBAL VOID send_avdrag(WORD wh, MKINFO *mk, WORD data_type)
{
if ((av_shell_id >= 0) && (av_shell_status & 512))
{
WORD app, d;
wind_get(wh, WF_OWNER, &app, &d, &d, &d);
memset(msgbuff, 0, (WORD)sizeof(msgbuff));
msgbuff[0] = AV_DRAG_ON_WINDOW;
msgbuff[1] = gl_apid;
msgbuff[3] = mk->mox;
msgbuff[4] = mk->moy;
msgbuff[5] = mk->kstate;
switch (data_type)
{
case DRAGDROP_PATH : /* ein Name */
#ifdef DEBUG_AV
Debug("qed: AV_DRAG_TO_WIN single file\n");
#endif
strcpy(global_str1, drag_filename);
*(UBYTE **) (msgbuff + 6) = global_str1;
break;
case DRAGDROP_DATA : /* mehrere Namen */
#ifdef DEBUG_AV
Debug("qed: AV_DRAG_TO_WIN multible files\n");
#endif
glob_data = malloc_global(drag_data_size + 1);
if (glob_data != NULL)
{
strcpy(glob_data, drag_data);
*(UBYTE **) (msgbuff + 6) = glob_data;
}
break;
}
send_msg(av_shell_id);
}
}
GLOBAL VOID send_vastart(WORD id, CONST UBYTE *data)
{
memset(msgbuff, 0, (WORD)sizeof(msgbuff));
msgbuff[0] = VA_START;
msgbuff[1] = gl_apid;
strcpy(global_str1, data);
*(UBYTE **)(msgbuff + 3) = global_str1;
send_msg(id);
}
GLOBAL VOID hndl_av(WORD msg[])
{
UBYTE *str_p;
switch (msg[0])
{
case VA_START :
if (all_iconified)
uniconify_window(NULL, NULL); /* aufwachen! */
str_p = *(UBYTE **)(msg + 3);
if (str_p != NULL)
{
PATH va_arg;
strcpy(va_arg, str_p);
if (strlen(va_arg) > 0)
{
#ifdef DEBUG_AV
Debug("qed: va_arg= %s\n", va_arg);
#endif
add_diskinfo(va_arg, FALSE);
open_multidisk();
}
}
break;
case VA_PROTOSTATUS :
#ifdef DEBUG_AV
Debug("qed: VA_PROTSTATUS %u\n", av_shell_status);
#endif
av_shell_status = msg[3];
if (wind_cycle && !(av_shell_status & 64))
wind_cycle = FALSE; /* glob. Fensterwechsel abschalten */
break;
case VA_DRAG_COMPLETE :
#ifdef DEBUG_AV
Debug("qed: VA_DRAG_COMPLETE.\n");
#endif
if (glob_data != NULL)
{
Mfree(glob_data);
glob_data = NULL;
}
break;
default:
break;
}
}
GLOBAL VOID init_av(VOID)
{
WORD i, d;
UBYTE name[9], *p;
if ((appl_xgetinfo(4, &d, &d, &i, &d)) && (i == 1)) /* gibts appl_search? */
{
if (appl_search(2, name, &d, &i) >= 1)
av_shell_id = i;
}
else
{
p = getenv("AVSERVER");
if (p != NULL)
{
strcpy(name, p);
for (i = (WORD)strlen(name); i < 8; i++)
strcat(name, " ");
i = appl_find(name);
if (i >= 0)
av_shell_id = i;
}
}
send_avprot();
}
GLOBAL VOID term_av(VOID)
{
send_avexit();
}